<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\User;
/* @var $this yii\web\View */
/* @var $searchModel app\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model app\models\User */
$this->title = '用户';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('创建机器人', ['create-robot'], ['class' => 'btn btn-success']) ?>
        <?= Html::a('创建用户', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'userid',
            'name',
            [
                'attribute'=>'img',
                'format' => 'raw',
                'value'=>function($model){
                    return '<div class="thumbnail">'
                        .Html::img(\app\models\UploadForm::SHOW_DIR.$model->img,['width'=>'300px','height'=>'100px'])
                        .'</div>';
                },
                'filter'=>false,
            ],
            [
                'attribute' => 'sex',
                'value'=>function($model){
                    /* @var $model app\models\User */
                    return $model->dropdown('sex',$model->sex);
                },
                'filter'=>User::dropdown('sex'),
                'filterInputOptions'=>['prompt'=>'性别','class'=>'form-control'],
                'headerOptions'=>['width'=>'10%'],
            ],
            [
                'label'=>'地区',
                'value'=>function($model){
                    /* @var $model app\models\User */
                    return $model->province.$model->city.$model->county;
                },
                'filter'=>'<div class="form-group">'
                            .Html::dropDownList('UserSearch[province]',null,[],['class'=>'form-control col-sm-4','id'=>'province'])
                            .Html::dropDownList('UserSearch[city]',null,[],['class'=>'form-control col-sm-4','id'=>'city'])
                            .Html::dropDownList('UserSearch[county]',null,[],['class'=>'form-control col-sm-4','id'=>'county']).
                            '</div>',
                'headerOptions'=>['width'=>'10%'],
            ],
            [
                'attribute' => 'type',
                'value'=>function($model){
                    /* @var $model app\models\User */
                    return $model->dropdown('type',$model->type);
                },
                'filter'=>User::dropdown('type'),
                'filterInputOptions'=>['prompt'=>'类型','class'=>'form-control'],
                'headerOptions'=>['width'=>'10%'],
            ],
            [
                'attribute' => 'created_at',
                'format' => ['date', 'php:Y-m-d']
            ],
            [
                'attribute' => 'updated_at',
                'format' => ['date', 'php:Y-m-d']
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
<?php $this->beginBlock('js')?>
<?=Html::jsFile('@admin/js/area.js')?>
<script>
    _init_area();
    $("#province").val("<?=$searchModel->province?>");
    change(1);
    $("#city").val("<?=$searchModel->city?>");
    change(2);
    $("#county").val("<?=$searchModel->county?>");
</script>
<?php $this->endBlock();?>
